import numpy as np	

"""
	Name is the model name, as long as 63 characters.
	Description is a short description of what the model is. Useful!
	Parameters is a 32 element structure, dtype "model_params". 
	You can look for the fields in the structure doc.
	Phase coords is defined as a python object, but most of the
	time it will be a N_model x 7 matrix containing the phase
	coordinates of the particles within the model.
"""

G = 6.6775e-11

model_type = np.dtype( [ \
				   ('Name'        , np.str_ , 64 ), \
				   ('Description' , np.str_ , 512), \
				   ('Np'          , np.int32     ), \
				   ('Status'      , np.str_, 3   ), \
				   ('Hidden'      , np.str_, 3   ), \
				   ('Type'        , np.str_,32   )] ) 

class MODELS:
		
	def __init__( self ):
		
		self.mtype  = np.zeros( (1,), dtype = model_type )
		self.params = []
		self.phcoor = []

	def kepler_disk( self, Np, a, Mc, Md ):
		
		self.mtype['Name']   = "Keplerian Disk"
		self.mtype['Description'] = "Simple keplerian disk."
		self.mtype['Np']  = Np+1
		self.mtype['Status'] = 'on'
		self.mtype['Hidden'] ='off'
		self.mtype['Type'] =  'massive'
		
		self.params = {'Particles' : Np,'Radius' : a, 'Central mass' : Mc, 'Disk mass' : Md}
		
		speed = np.zeros(Np)
		radii = np.random.random(Np) * a
		angle = np.random.random(Np) * 2 * np.pi

		x,y,z = [radii*np.cos(angle),radii*np.sin(angle),np.zeros(Np)]
	
		vx    = np.sqrt( G*Mc/radii ) * np.sin(angle)
		vy    =-np.sqrt( G*Mc/radii ) * np.cos(angle)
		vz    = np.zeros(Np)

		M     = np.ones(Np) * Md/Np
		
		M     = np.append(M,Mc)
		
		x     = np.append(x,0.0)
		y     = np.append(y,0.0)
		z     = np.append(z,0.0)
		
		vx    = np.append(vx,0.0)
		vy    = np.append(vy,0.0)
		vz    = np.append(vz,0.0)
		
		self.phcoor = (np.float64) (np.asanyarray([M,x,y,z,vx,vy,vz]).T)
		
		print self.phcoor.shape
		
	def cold_sphere( self, Np, a, M      ):
		
		self.mtype['Name'] = "Cold Sphere"
		self.mtype['Description'] = "Simple cold sphere."
		self.mtype['Np'] = Np
		self.mtype['Status'] = 'on'
		self.mtype['Hidden'] = 'off'
		self.mtype['Type'] = 'massive'
		
		self.params = {'Particles' : Np,'Radius' : a, 'Mass' : M}
		
		v     = np.zeros(Np)
		r     = np.random.random(Np) * a
		phi   = np.random.random(Np) * 2 * np.pi
		tht   = np.random.random(Np) * 1 * np.pi

		[x,y,z]    = [r*np.cos(phi)*np.sin(tht),r*np.sin(phi)*np.sin(tht),r*np.cos(tht)]
		
		[vx,vy,vz] = [v,v,v]
		
		M = np.ones(Np) * M/Np
		
		self.phcoor = np.asanyarray([M,x,y,z,vx,vy,vz]).T
		print self.phcoor.shape
